package services.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import dao.ShopCarDao;
import dao.impl.GoodsDaoImpl;
import dao.impl.ShopCarDaoImpl;
import entity.Goods;
import entity.ShopCar;
import services.ShopCarService;

public class ShopCarServiceImpl implements ShopCarService{
	private ShopCarDao shopDao = new ShopCarDaoImpl();
	private GoodsDaoImpl goodsDao = new GoodsDaoImpl();
	@Override
	public int insertToCar(int user_id,int goods_id) {
		int res = 0;
		try {
			res = shopDao.insertIntoShopCar(user_id,goods_id);
			if(res > 0) return res;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return 0;
	}
	@Override
	public List<Goods> showCarGoods(int user_id) {
		int res = 0;
		List<Goods> carGoodsList = new ArrayList<Goods>();
		try {
			List<ShopCar> goodsIdList = shopDao.getGoodIdFromShopCar(user_id);
			if(goodsIdList!=null) {
				
				for(ShopCar sc : goodsIdList) {
					int goods_id = sc.getGoods_id();
					carGoodsList.add(goodsDao.getGoodsById(goods_id));
				}
				
				return carGoodsList;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
